package com.example.tdck.controller;

import com.example.tdck.pojo.Event;
import com.example.tdck.service.EventService;
import com.example.tdck.utils.ResponseHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @ClassName EventsController
 * @author lbt
 * @Date Last updated in 2023/1/27
 * @Description Controller层，和前端交互，响应请求，以json格式返回事件 @CrossOrigin注解解决跨域问题
 */


@CrossOrigin
@RestController
@RequestMapping("/api/tdck/")
public class EventController {
    @Autowired
    private EventService eventService;

    @GetMapping("/event/common")
    public ResponseHelper<Event> getCommonEvent()  {
        return new ResponseHelper<>(eventService.getRandomEvent()) ;
    }

    @GetMapping("/event")
    public ResponseHelper<Event> getMajorEvent(@RequestParam("major") int major) {
        return new ResponseHelper<>(eventService.getRandomEvent(major));
    }

    @GetMapping("/test")
    public ResponseHelper<String> getTestEvent(){
        return new ResponseHelper<>("test");
    }



}
